How to execute other statement in an if loop if a condition is satisfied
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
if not(spcng_prov <= bar_dia) && d_prov >= d_req && Ast_prov >= Ast_req
fprintf('Since the actual depth provided is greater than the depth required and the Area of Tension Steel provided is greater than the Area of Tension Steel required. Hence it is evident without further proof that the section is safe in flexure.')
elseif spcng_prov < bar_dia
fprintf('Since the spacing provided is less than the Minimum spacing required, hence the bar diameter has to br changed to meet the spacing requirements')
bar_dia = 25;
fprintf('New Diameter of Bar = %d' , bar_dia)
if (Ast_min < Ast_req) && (Ast_req <Ast_max)
bars_numbr = ceil(Ast_req/((pi/4)*bar_dia^2));
Ast_prov = bars_numbr*(pi/4)*bar_dia^2;
elseif Ast_min > Ast_req
bars_numbr = ceil(Ast_min/((pi/4)*bar_dia^2));
Ast_prov = bars_numbr*(pi/4)*bar_dia^2;
elseif Ast_req > Ast_max
bars_numbr = ceil(Ast_max/((pi/4)*bar_dia^2));
Ast_prov = bars_numbr*(pi/4)*bar_dia^2;
end
fprintf('Number of Steel Bars provided = %d' , bars_numbr);
fprintf('Area of tension Steel provided = %d' , Ast_prov);
spcng_prov =ceil(vpa((b - (2*clr_cover + bars_numbr*bar_dia + 2*stirup))/(bars_numbr - 1)))
fprintf('Since the actual depth provided is greater than the depth required and the Area of Tension Steel provided is greater than the Area of Tension Steel required. Hence it is evident without further proof that the section is safe in flexure.')
elseif spcng_prov < bar_dia
fprintf('Since the spacing provided is less than the Minimum spacing required, hence the bar diameter has to br changed to meet the spacing requirements')
bar_dia = 32;
fprintf('New Diameter of Bar = %d' , bar_dia)
if (Ast_min < Ast_req) && (Ast_req <Ast_max)
bars_numbr = ceil(Ast_req/((pi/4)*bar_dia^2));
Ast_prov = bars_numbr*(pi/4)*bar_dia^2;
elseif Ast_min > Ast_req
bars_numbr = ceil(Ast_min/((pi/4)*bar_dia^2));
Ast_prov = bars_numbr*(pi/4)*bar_dia^2;
elseif Ast_req > Ast_max
bars_numbr = ceil(Ast_max/((pi/4)*bar_dia^2));
Ast_prov = bars_numbr*(pi/4)*bar_dia^2;
end
fprintf('Number of Steel Bars provided = %d' , bars_numbr);
fprintf('Area of tension Steel provided = %d' , Ast_prov);
spcng_prov =ceil(vpa((b - (2*clr_cover + bars_numbr*bar_dia + 2*stirup))/(bars_numbr - 1)))
fprintf('Since the actual depth provided is greater than the depth required and the Area of Tension Steel provided is greater than the Area of Tension Steel required. Hence it is evident without further proof that the section is safe in flexure.')
end
after executing the condition of bar dia 25 i want to check again for spacing and then execute accordinly if the statement is true or false
0 Kommentare
Antworten (1)
Amith
am 9 Sep. 2024
Hi Imaad,
I understand that you want to re-execute the code starting from the first if statement each time bar_dia is set to 25. To accomplish this, you can use a variable called reexecute and place the entire code inside a while loop, as shown in the code snippet below:
reexecute = true;
while reexecute
reexecute = false; % Reset the flag
if not(spcng_prov <= bar_dia) && d_prov >= d_req && Ast_prov >= Ast_req
fprintf('Since the actual depth provided is greater than the depth required and the Area of Tension Steel provided is greater than the Area of Tension Steel required. Hence it is evident without further proof that the section is safe in flexure.\n');
elseif spcng_prov < bar_dia
fprintf('Since the spacing provided is less than the Minimum spacing required, hence the bar diameter has to be changed to meet the spacing requirements\n');
bar_dia = 25;
fprintf('New Diameter of Bar = %d\n', bar_dia);
reexecute = true; % Set the flag to re-execute the loop
end
if reexecute
continue; % Skip the rest of the loop and re-execute from the beginning
end
% Your existing calculations and conditions
if (Ast_min < Ast_req) && (Ast_req < Ast_max)
bars_numbr = ceil(Ast_req / ((pi / 4) * bar_dia^2));
Ast_prov = bars_numbr * (pi / 4) * bar_dia^2;
elseif Ast_min > Ast_req
bars_numbr = ceil(Ast_min / ((pi / 4) * bar_dia^2));
Ast_prov = bars_numbr * (pi / 4) * bar_dia^2;
elseif Ast_req > Ast_max
bars_numbr = ceil(Ast_max / ((pi / 4) * bar_dia^2));
Ast_prov = bars_numbr * (pi / 4) * bar_dia^2;
end
fprintf('Number of Steel Bars provided = %d\n', bars_numbr);
fprintf('Area of tension Steel provided = %d\n', Ast_prov);
spcng_prov = ceil(vpa((b - (2 * clr_cover + bars_numbr * bar_dia + 2 * stirup)) / (bars_numbr - 1)));
fprintf('Since the actual depth provided is greater than the depth required and the Area of Tension Steel provided is greater than the Area of Tension Steel required. Hence it is evident without further proof that the section is safe in flexure.\n');
end
This code uses a while loop with a flag (reexecute) to control whether the code should be re-executed from the beginning. When bar_dia is set to 25, the flag is set to true, causing the loop to restart.
I hope this helps!
0 Kommentare
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!