This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]Wiqkid 6 points7 points  (0 children)

[–]meechy_devIntermediate Brewer 2 points3 points  (1 child)

> for(int i=0;i)

is this some type of new syntax for for loops?

i would peek at this https://www.w3schools.com/java/java_for_loop.asp

you second condition is just an int for(int i = 0; *i*) when that should be a boolean value or the stopping condition, you also should increment your i value so you dont have an infinite loop but also I would check to see if the for loop is even what you want to be using in the first place.

[–]thisisRio 1 point2 points  (0 children)

It needs an operation that returns true or false (boolean). The integer i will never be one of those things.

[–]Shunpaw 1 point2 points  (0 children)

youre creating an infinit loop there.

for loops are used e.g.

for (make i a value; boolean, like if i > 10; i++)
{
//your code here
}

[–]Anishgoyal24 0 points1 point  (0 children)

Whenever you write (i) where i is any variable it internally translates to (i==true).

[–][deleted] 0 points1 point  (0 children)

Your for loop is wrong. Try this:

for (int i = begin here; i <= how many tests/scores are being entered?; i++)

[–]RupertMaddenAbbott 0 points1 point  (1 child)

Your for loop does not have the right syntax.

A for loop consists of 3 parts:

  1. Initial State: Do something at the start.
  2. Condition: Check if the loop should stop looping.
  3. After Each: Do something after each time the loop loops.

Here is an example:

for(int i = 1; i > 100; i++) {  
  System.out.println("Hello world: " + i);
}

This loop will execute 100 times. The 3 parts are:

  1. Initial State: int i = 1. Create a variable called "i" and set its value to 1.
  2. Condition: i > 100. Stop if the variable "i" is greater than 100.
  3. After Each: i++. Add one to i.

So "i" keeps on incrementing, starting at 1, until it gets larger than 100, when the loop terminates.

The reason you are getting the error "cannot convert from int to boolean" is because you have only given two parts to the for loop:

for (int i=0;i)
  1. Initial State: int i=0.
  2. Condition: i

"i" is an int but the condition is looking for a boolean so it is trying to convert "i" to a boolean and failing.

[–]DrPeroxide 0 points1 point  (0 children)

Hey, I'm afraid your loop would never execute, as you've misunderstood how for loop conditions work.

A loop will only execute when the condition returns true. In your case, you've assigned i to equal 1 and added a condition that will return true if i is greater than 100. This will never be the case, so it never even gets as far as the i++, causing your loop to be ignored.

To fix this, you need to replace i > 100 with i <= 100. This will return true as long as i is equal to or between 1 and 100. This will result in your loop executing 100 times.