You need to sign in to do that
Don't have an account?
Bhanu joshi 10
Doubt on for Loop
I have written following Code
integer count 0;
condition 1:
for(Account a :[Select name from account limit 10]){
count++;
System.debug('Count '+count);
}
condition 2:
for(list<Account> a :[Select name from account limit 10]){
count++;
System.debug('Count '+count);
}
On condition 1 i get output as 10 and for condition 2 i get output 1. Why?
Any help will be appricated
Thanks
integer count 0;
condition 1:
for(Account a :[Select name from account limit 10]){
count++;
System.debug('Count '+count);
}
condition 2:
for(list<Account> a :[Select name from account limit 10]){
count++;
System.debug('Count '+count);
}
On condition 1 i get output as 10 and for condition 2 i get output 1. Why?
Any help will be appricated
Thanks
In condition one you are using one sObject record to store data returned by query and hence loop is running for each record returned.
but in condition 2: you are getting List of 10 record in one time.