madiya madiya madiya madiya - 5 months ago 58
Android Question

For loop not executed

I am facing a problem as my for loop is not executed.
Here is my code:

public void sendSMS(){

for(int t = 1; t == 5; t = t+1) {

public void pp() {

SmsManager smsManager = SmsManager.getDefault();

phoneNo = "01234567890";
message ="Sample msg from app";
Toast.makeText(getApplicationContext(), "testing done", Toast.LENGTH_LONG).show();

smsManager.sendTextMessage(phoneNo, null, message, null, null);
Toast.makeText(getApplicationContext(), "dummy Message dumped!",


Please help.


I'm not sure what you are going for exactly but this is your problem in your loop

t == 5

it should be something like

for(int t = 1; t <= 5; t = t+1) {

t is never 5 here so it will never iterate. Also, you can simplify the last part so it looks like

for(int t = 1; t <= 5; t++) {

If you look at the Java docs for a for loop

for (initialization; termination; increment) { statement(s) }

Now look what it says for the termination expression

When the termination expression evaluates to false, the loop terminates.

The termination expression is false from the beginning meaning it won't run.