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
Jaffer Ali.Jaffer Ali. 

Code script statement Governor limit

Hello Every One,

 

I am thinking to resolve one mystery in Apex which I don't know why it is happening like that.Please consider two sample code . I am getting total number of script statement equal to 101 in both piece of code .For first one it makes sense to me but not sure why it is giving 101 in second sample code.

 

Sample 1

-------------------

for(Integer i=0 ;i < 100 ;i++){


}

 

Sample 2 

---------------

for(Integer i=0 ;i < 100 ;i++){


    System.debug('My name is Jaffer');
}

 

 

Please share your thoughts.

 

Thanks

Jaffer

Varun YagainVarun Yagain

Hello Jaffer,

 

I'm not sure I understand. Are you referring to the 'Number of the code statements: ' count?

 

Wouldn't the empty for-loop then count as a block with a do-nothing statement? A looping over is expected even when we don't put any code in, right? I'm sorry if I am missing something here.

 

-Varun Yagain.

Jaffer Ali.Jaffer Ali.

Varun,

 

You are right, I am referring to the Number of Code Statements count.

 

I just want to understand the reason that why Sample 1 and Sample 2 both have 101 code script statements. Although sample 2 has one line in for loop so it should have 201 code script statements .Isn't it?

 

Regards,

jaffer

Varun YagainVarun Yagain

Jaffer,

 

I find it appropriate.

 

There is no 'empty' loop as long as we are looping. The 'empty' loop can be imagined as having one 'do-nothing' line, counted as 1. And if indeed there is a line (as in your example 2), then that is the only line count (as 1).

 

It works fine if I add a second system.debug( ) (showing the count as 201).

 

Perhaps it makes sense?

 

Please mark the issue solved if it solves your problem.

 

-Varun Yagain