Advertisement
Shell01

Bucles Anidados

Jan 31st, 2021
2,516
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
GAMBAS 1.48 KB | None | 0 0
  1. 'Ejemplos de bucles anidados
  2.  
  3.  
  4. Public Sub _new()
  5.  
  6. End
  7.  
  8. Public Sub Form_Open()
  9.  
  10. 'bucle_repeat
  11. 'bucle_while
  12. bucle_for 'Este es el que se ejecuta
  13. 'bucle_for_each
  14.  
  15. End
  16.  
  17. Public Sub bucle_for()
  18.  
  19. Dim a As Integer
  20. Dim b As Integer
  21.  
  22. For a = 1 To 10 'Repetir de una a diez veces
  23.       For b = 1 To 10 'Repetir de una a diez veces
  24.             Print a & " * " & b & " = " & (a * b)
  25.       Next
  26.       Print 'Para dejar un espacio en blanco
  27. Next
  28.  
  29. End
  30.  
  31. Public Sub bucle_dowhile()
  32.  
  33. Dim a As Integer
  34. Dim b As Integer
  35. a = 1
  36. b = 1
  37.  
  38. Do While a <= 10 'Hacer mientras a sea mayor o igual a 10
  39.       Do While b <= 10 'Hacer mientras a sea mayor o igual a 10
  40.             Print a & " * " & b & " = " & (a * b)
  41.             b = b + 1
  42.       Loop
  43.       Print
  44.       b = 1
  45.       a = a + 1
  46. Loop
  47.  
  48. End
  49.  
  50. Public Sub bucle_repeat()
  51.  
  52. Dim a As Integer
  53. Dim b As Integer
  54. a = 1
  55. b = 1
  56.  
  57. Repeat 'Repetir
  58.       Repeat 'Repetir
  59.              Print a & " * " & b & " = " & (a * b)
  60.              a = a + 1
  61.       Until (a > 10) 'Hasta que a sea mayor a 10
  62.       Print 'Para dejar un espacio en blanco
  63.       a = 1
  64.       b = b + 1
  65. Until (b > 10) 'Hasta que b sea mayor a 10
  66.  
  67. End
  68.  
  69. Public Sub bucle_for_each()
  70.  
  71. Dim tabla As Integer[] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
  72. Dim a, b As Integer
  73.  
  74. For Each a In tabla ' Por cada numero entero en la tabla
  75.        For Each b In tabla
  76.              Print a & " * " & b & " = " & (a * b)
  77.        Next
  78.        Print 'Para dejar un espacio en blanco
  79. Next
  80.  
  81. End
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement