2

How do I write a 'for' loop that starts counting from the given 'start' number? Without the first statement in the loop, the code will result in an error. Writing 'start = 0;' starts the counting from 0. Thanks in advance!

enter image description here

enter image description here

2 Answers 2

2

You can leave the initial statement blank and just put a semicolon.

for(; start <= end; start++)
Sign up to request clarification or add additional context in comments.

Comments

0

Just do:

for(int i = start; i <= end; i++){
    end--;
    System.out.print(start);
}

Although in actuality if you want your code to work you have to do:

for(int i = start; i <= end; i++){
    System.out.print(start);
}

3 Comments

the second ones works! didnt think of that, thank you!
it allows me to do so after 10 mins but will do :)
@MAnn :P Glad to help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.