Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Problem with = integer in a for loop

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all

What am I doing wrong here?

i try to do this:

But it keeps trowing out errors.
When I use

it compiles but the for loop will never be used.
The only workaround I found is doing this

but that is not the best way to do it I assume.

I really wan't to understand this issue.

Kind regards
 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

jarco voorhees wrote:

but that is not the best way to do it I assume.
I really wan't to understand this issue.

Kind regards



The syntax would be- for(initialisation;condition;increment){}

In the first case you are doing an assignment when a condition is required, so it doesnt compile.

In the other two cases- It depends on what the value of getal is. It might have been 0. There's is not best way in terms of using for-loop. It all depends on how its going to work in your code situation.

Edit: ==- will not work as it will not evaluate the condition. ==- will be false and hence will not evaluate the loop body.
 
jarco voorhees
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I will paste the complete code because I want to get to the bottom of this now.




 
jarco voorhees
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry I think I solved it myself.
I forgot to think about the fact that the number will not always be Equal to the value of waarde. It will work with >= .
 
Mohamed Sanaulla
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

jarco voorhees wrote:Sorry I think I solved it myself.
I forgot to think about the fact that the number will not always be Equal to the value of waarde. It will work with >= .



Yeah, you are right. Just edited my reply.
 
Hang a left on main. Then read this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic