Learning java, clarification needed

How come “while(i>=0)” is correct,
but “while(0<=i)” is incorrect?

+// Setup
var myArray = [];
var i=5
while(i >= 0){
myArray.push(i);
i--;
}
// Only change code below this line
  **Your browser information:**

User Agent is: Mozilla/5.0 (Linux; Android 11; SM-G975U) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.88 Safari/537.36

Challenge: Iterate with JavaScript While Loops

Link to the challenge:

i can point at different things such as 1 or 2 or 3 ect. but 0 will only ever be 0 which is why you would generally have i on the left hand side.

Just to be clear you can write this while(0<=i) just fine it wont cause an error

1 Like

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.