Guys why do i get an error when i type this code, that i x is not declared, and its declared in the for loop, help me pls am new | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Guys why do i get an error when i type this code, that i x is not declared, and its declared in the for loop, help me pls am new

public class Program { public static void main(String[] args) { for(int x = 1; x <=5; x++) { System.out.println(x); } } }

26th Aug 2018, 11:22 AM
Ryahama Tony
Ryahama Tony - avatar
3 Answers
+ 6
This program is running just fine for me. What are you using to run it?
26th Aug 2018, 11:27 AM
Eduardo Petry
Eduardo Petry - avatar
+ 2
Thanks Cruz and Eduardo, i was putting a semicolon after the For loop, thats why i was getting the error. but now it works perfectly.
26th Aug 2018, 8:49 PM
Ryahama Tony
Ryahama Tony - avatar
+ 1
It worked for me.
26th Aug 2018, 11:26 AM
Ulisses Cruz
Ulisses Cruz - avatar