the purpose of my program is to ask the user for their numerical grades (depending on how many total grades they have) and then they are given their letter grade. but i cant get the for loop to loop the question according to their number of total grades

import TerminalIO.*;
public class LetterGradeWLT {
  public static void main(String [] args){
 

  
  KeyboardReader reader = new KeyboardReader();
  
  int grades;
  int grade;
  String lettergrade;
    
  grades = reader.readInt("Enter total number of grades: ");
    

    
   for ( grades = 1; grades >= 1; grades++) {

     grade = reader.readInt("Enter your numeric grade: ");

    
    if (grade >= 96)
      System.out.println(" Your letter grade is A+.");
    if ( 92 <= grade && grade <= 95)
      System.out.println(" Your letter grade is A.");
    if ( 90 <= grade && grade <= 91)
      System.out.println(" Your letter grade is A-.");
    if ( 86 <= grade && grade <= 89)
      System.out.println(" Your letter grade is B+.");
    if ( 82 <= grade && grade <= 85)
      System.out.println(" Your letter grade is B.");
    if ( 80 <= grade && grade <= 81)
      System.out.println(" Your letter grade is B-.");
    if ( 76 <= grade && grade <= 79)
      System.out.println(" Your letter grade is C+.");
    if ( 72 <= grade && grade <= 75)
      System.out.println(" Your letter grade is C.");
    if ( 70 <= grade && grade <= 71)
      System.out.println(" Your letter grade is C-.");
    if ( 66 <= grade && grade <= 69)
      System.out.println(" Your letter grade is D+.");
    if ( 62 <= grade && grade <= 65)
      System.out.println(" Your letter grade is D.");
    if ( 60 <= grade && grade <= 61)
      System.out.println(" Your letter grade is D-.");
    if ( -1 < grade && grade <= 59)
      System.out.println(" Your letter grade is F.");
  }
}
}

for ( grades = 1; grades >= 1; grades++)

so you initialise grades to 1. (why? considering you ask the user for grades... you are overwriting what you want to know)

you want to loop if grades is greater or equal to 1.

each loop you want to increment grades by 1.

does this logic add up?

what should i initialize it as?

Make another counter int.
For example:

int grades;
  int grade;
int counter;
  String lettergrade;
 
  grades = reader.readInt("Enter total number of grades: ");
 
 
 
   for ( counter = 1; counter >= grades; counter++) {
etc.

that should do it I believe

that won't work, but the idea is there. you don't even need to introduce a separate counter, but you should really try work this out yourself.

note: you don't need to initialise inside a for loop if you don't want.

which is why i said it won't work...

think logically through your code and it should be pretty simple what is wrong.

You should try an normal loop, a nice loop with my friend the varible "i", then continue , until my varible "i" is less than grades, in the mean time the loop will be "looping".

number = 10;
sum = 0;
for (var i=1; i<= number; i++) {
sum = sum + number;
}
document.write("sum = " + sum);


number = 10;
for (var i=number; i > 0; i--) {
if ( i%2 == 1)
document.write(i);
}


product = 1;
number = 5;
for (var i=1; i < (number+1); i++) {
product = product * number;
}
document.write(product);


for ( var i=1; i<= 5; i++) {
for (var j=1; j<=3; j++) {
document.write("*");
}
document.write("<br />");
}

number = 10;
sum = 0;
for (var i=1; i<= number; i++) {
sum = sum + number;
}
document.write("sum = " + sum);


number = 10;
for (var i=number; i > 0; i--) {
if ( i%2 == 1)
document.write(i);
}


product = 1;
number = 5;
for (var i=1; i < (number+1); i++) {
product = product * number;
}
document.write(product);


for ( var i=1; i<= 5; i++) {
for (var j=1; j<=3; j++) {
document.write("*");
}
document.write("<br />");
}

I suppose you need to ask for the number of grades and then continue looping in the for loop for those many times.
Now, if you understand the for loop construct,
initialise a counter to 1 and continue it to the number of grades, incrementing it once every time.
Think on this and let us know the result.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.