function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
AMIT KUMAR ROY 10AMIT KUMAR ROY 10 

this code is run in developer console but when i wrote in Apex class it will return an Error likeError"Error: Compile Error: Expecting '}' but was: 'for' at line 4 column 1" please help me

public class TimeTableset_controller{
integer i=1;
integer count;
for(count=1;count<24;count++)
{
    if(count<12 || count>=12)
        if(count<12)
    system.debug(i+':00AM-'+(++i)+':00AM');
    if(count>=12)
        system.debug(i+':00PM-'+(++i)+':00PM');
    
}
}
Saurabh Gupta ManrasSaurabh Gupta Manras

Hello Amit,

                 try below code you wont get error , the problem was you didnt use any function or constructor .

public class TimeTableset_controller{
   public TimeTableset_controller(){
        integer i=1;
        integer count;
        for(count=1;count<24;count++)
        {
            if(count<12 || count>=12)
                if(count<12)
                system.debug(i+':00AM-'+(++i)+':00AM');
            if(count>=12)
                system.debug(i+':00PM-'+(++i)+':00PM');
            
        }
    }
}

AMIT KUMAR ROY 10AMIT KUMAR ROY 10
Thank you Sir
Saurabh Gupta ManrasSaurabh Gupta Manras
Please choose it as the Best answer, if you find it helpful .