Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: skip several lines of unnecessary code in thinBASIC

  1. #1

    skip several lines of unnecessary code in thinBASIC

    hi

    I'm a little lost as I skip several lines of unnecessary code in thinBASIC

    in vba:
              If T(a) Then _
                 If Not tem_valor(vq(a), v(a), Array_O, l + ll(a)) Then GoTo pula
              If T(b) Then _
                 If Not tem_valor(vq(b), v(b), Array_O, l + ll(b)) Then GoTo pula
              If T(c) Then _
                 If Not tem_valor(vq(c), v(c), Array_O, l + ll(c)) Then GoTo pula
    
              For c2 = 1 To Cf1
                   If T(1) Then CoL_De(L_d, c2) = Array_O(l - 1, c2): L_d = L_d + 1
                   If T(2) Then CoL_De(L_d, c2) = Array_O(l, c2): L_d = L_d + 1
                   If T(3) Then CoL_De(L_d, c2) = Array_O(l + 1, c2): L_d = L_d + 1
              Next
              L_d = L_d + 1
    
    pula:
         Next
    
    I know I can create a check variable
    But is there a more practical way?

  2. #2
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,530
    Rep Power
    171
    For some good reasons there's no Goto in thinBasic, if you want to skip Iteration in For-Next loop there are several ways.
    You may check for a condition using
    For var = start To end When {condition}
    Or you can skip code using:
    If {condition} Then Iterate ...

    Check thinBasic-help and code-examples how to use
    I think there are missing some Forum-sections as beta-testing and support

  3. #3
    Hi
    In this case I already have several checks inside an extended loop
    The only solution I see in my case is a lot of more checking inside a huge loop where what I'm looking for is execution speed
              tt = True
              If t(a) = True Then
                   If  tem_valor(vq(a), v(a), Array_O, l + ll(a)) = False Then
                        tt = False
                   End If
              End If
              
              If t(b) = True And tt = True Then
                   If  tem_valor(vq(b), v(b), Array_O, l + ll(b)) = False Then
                    tt = False
                   End If
              End If
    
              If t(c) = True And tt = True Then
                   If tem_valor(vq(c), v(c), Array_O, l + ll(c)) = False Then
                    tt = False
                   End If
              End If
              ...
              If tt = True Then
                   For c2 = 1 To Cf1
                        If t(1) Then CoL_De(L_d, c2) = Array_O(l - 1, c2): L_d = L_d + 1
                        If t(2) Then CoL_De(L_d, c2) = Array_O(l, c2): L_d = L_d + 1
                        If t(3) Then CoL_De(L_d, c2) = Array_O(l + 1, c2): L_d = L_d + 1
                   Next
                   L_d = L_d + 1
              End If
              
         Next
    
    I am not a professional programmer, and I have limitations on remembering things,
    Like names of functions, variables, so I always end up doing my own and I end up using short variables "which is also something highly reprimanded"

    I do not see how this can be so scary in a few lines of code
    Do knives kill people, or do people kill people?
    Should the knives be abolished?
    Will Goto have already destroyed some super computer, invaded systems, made a bug code?

    But ok I will not discuss
    I'll find another solution for me.

    bye

  4. #4
    @EdCronos: With Exit you can exit a FOR loop and continue after the Next statement. Iterate returns to the FOR statement to continue the iteration.

  5. #5
    11/5000
    Hi
    Thank you

    In this case it is not just a question of getting out of the fuction
    Would be like avoiding additional tests in an "AND"


    Function And(test1, test2, test3, ...)

    If test1 = false then function And = false: exit function
    If test2 = false then function And = false: exit function
    If test3 = false then function And = false: exit function
    function And = true

    End function

    Or an "OR"
    Function Or(test1, test2, test3, ...)

    If test1 = true then function OR = true: exit function
    If test2 = true then function OR = true: exit function
    If test3 = true then function OR = true: exit function
    function OR = false

    End function


    Are for testing and arrays filters
    Must have a way to do this more easily, but I am limited by my own ability

    Although I am inexperienced in programming, I see that programmers are more concerned with imposing their own concepts than trying to set a minimum standard in all these languages
    How many languages are there?
    How many types of syntax?
    In the end all have to convert to machine language

    But anyway I think I'll have to continue on the same vba,
    This is why I ran into other issues,
    And get relearning and breaking the head, just to play to assemble small functions that end up dropping aside

    I have tried to look at Oxygen Basic but I have not been able to define an initial operation, mainly for the question of Byref multimimensional arrays and variant type


    I wonder when they will abolish the "if then else" as well

    This is because the goto and gosub complaint is that it leaves the code confusing
    But if in a few line function this is impossible
    With the "if then else" is able to leave it almost like a puzzle

        If Col_Array2 > 0 Or Col_fim_Array2 > 0 Then
              If Col_Array2 > 0 Then Cx = Col_Array2 Else Cx = Col_fim_Array2
    
              If Col_Array2 = 0 Or Col_fim_Array2 = 0 Then
                   For c = 1 To m
                        If Matriz_1(c) = array2(Linha_array2, Cx) Then tem_valor = True: Exit Function
                   Next
                   Exit Function
              Else
                   If Col_Array2 = 0 Then Col_Array2 = 1
                   If Col_Array2 <> Col_fim_Array2 Then
                        If Col_Array2 > Col_fim_Array2 Then
                             d = -1: dm = Col_Array2: mx = Col_Array2 - Col_fim_Array2
                        Else
                             d = 1: dm = Col_fim_Array2: mx = Col_fim_Array2 - Col_Array2
                        End If
                        c1 = Col_Array2: c2 = Col_fim_Array2
                   End If
              End If
         End If
         If m < mx Then mx = m
    
    Oi
    nesse caso não é apenas questão de sair da função
    seria como evitar testes adicionais em uma função "AND"

    são para teste e filtros de arrays
    deve ter uma maneira de fazer isso mais facilmente, mas eu sou limitado por minha própria capacidade

    apesar de eu ser inexperiente em questão de programação,eu vejo que os programadores estão mais preocupados em impor seus próprios conceitos do que tentar definir um padrão mínimo em todas essas linguagens
    quantas linguagens existem?
    quantos tipos de sintaxe ?
    no final todas tem que converter para linguagem de maquina

    mas de qualquer forma acho que vou ter que continuar no vba mesmo,
    isso por que esbarrei em outras questões,
    e ficar reaprendendo e quebrando a cabeça, apenas para brincar de montar pequenas funções que no final acabam largadas de lado
    tentei olhar o Oxygen Basic mas também não consegui definir um funcionamento inicial, principalmente para a questão dos arrays multdimencionas Byref e tipo variant


    Fico imaginando quando vão abolir o "if then else" tambem

    isso porque a reclamação do goto e gosub é que deixa o codigo confuso
    mas se em uma função de poucas linha isso é impossivel
    com o "if then else" é capaz de deixar lo quase como um quebra cabeça
    Last edited by Edcronos; 20-01-2017 at 12:32.

  6. #6
    Rene showed you how to avoid the checking by using Iterate in your first example. Or did you ment something else?

  7. #7
    Unfortunately I could not find a practical example of "Iterate"
    But I can not help crying about my own lack of capacity

    When I tried C ++ I even managed to locate myself, but I did not adapt to the "{}"
    For me it was difficult to keep track of where in the code I was

    When I tried another platform focused on the basic I did not expect so much discrepancy in the base, I just expected different extra capabilities

    I basically use only FOR NEXT, IF THEN, ELSE, and ARRAYS, and even for those simple things I struggle with defining a functional code by the differences of declaring the variables and returning values ​​outside the constraints of requirements in the lines of code

    The vba until you answer me for the things I like to put together, I just wanted to carry some things I did for dll's to make it easier to use in the different experiments
    One of them would be a macro that reallocates array data by parameters

    But without stress for my limitations and without needing so much capacity the ideal is to continue where I am

    Thank you for your attention.

    infelizmente não consegui achar um exemplo pratico sobre "Iterate"
    mas não adianta eu ficar chorando sobre minha propria falta de capacidade

    quando eu tentei o C++ eu até consegui me situar , mas não me adaptei aos "{}"
    para mim ficava dificil acompanhar em que parte do codigo eu estava

    quando eu tentei outra plataforma enfocada no basic eu não esperava tanta discrepacia na base, esperava apenas capacidades extras diferentes

    eu basicamente uso apenas FOR NEXT, IF THEN ELSE, e ARRAYS e mesmo para essas coisas tão simples enfrento dificuldades para definir um codigo funcional pelas diferenças de declarar as variaveis e retonar valores fora as difereças de exigencias nas linhas de codigo

    o vba até que me atende para as coisas que eu gosto de montar, eu apenas queria portar algumas coisas que eu fiz para dll´s para ficar mais facil usar nos diferentes experimentos
    uma delas seria uma macro que realoca dados de array por parametros

    mas sem stress para minhas limitações e sem necessidade de tanta capacidade o ideal é continuar onde estou

    mesmo assim obrigado pela atenção

  8. #8
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    Edcronos,

    let me help you. The advice given in this thread is a good one. For your case, this would be the way to jump to the nearest NEXT:
    If T(a) Then _
      If Not tem_valor(vq(a), v(a), Array_O, l + ll(a)) Then iterate for
      
    If T(b) Then _
      If Not tem_valor(vq(b), v(b), Array_O, l + ll(b)) Then iterate for
      
    If T(c) Then _
      If Not tem_valor(vq(c), v(c), Array_O, l + ll(c)) Then iterate for
    
    If it is still too confusing, let me show you on this example:
    uses "console"
    
    long flagField(8) = 1, 1, 1, 0, 0, 1, 0, 1
    long i
    
    for i = 1 to 8
      if flagField(i) = 0 then iterate for ' -- Skip flags which are not set, by moving on to the next iteration (which equals GOTO to label right before NEXT)
      printl strformat$("Flag {1} is set", i)
    next
    
    waitkey
    
    And this is even more ellegant, as adviced by Rene:
    uses "console"
    
    long flagField(8) = 1, 1, 1, 0, 0, 1, 0, 1
    long i
    
    for i = 1 to 8 when not flagField(i) = 0  
      printl strformat$("Flag {1} is set", i)
    next
    
    waitkey
    
    Last but not least: There is a nice example on Iterate in the help file. How to reach it? Just open your script in ThinAIR, put cursor on the word Iterate and press F1. There is a context sensitive help system ready for you.


    Petr
    Last edited by Petr Schreiber; 22-01-2017 at 17:37.
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  9. #9
    Sorry, maybe I'm too stupid, but for me it got a bit confusing as to how to apply it the way I want it
    I did not understand, how to include sets of totally different conditions in this "Iterate"

    If at least it had an assembly structure, with an output and input switch

    For n = 1 to 1000
    
    Set switch (primario)
    Switch (1,5) ON
    End switch
    
    Set switch (segundario)
    Switch (2,3,4) ON
    End switch
    
    
    Set switch (1)
    If false then switch (1,3) off "exits the switch instruction set and switches off the execution of swtch(3)
    ...
    End switch
    ...
    Set switch (2)
       If true then switch (2) off,
       for nn to
          If ten(nn)=false then switch (2,4) off,
       next
       If false then switch (2,4) off,
    End switch
    
    Set switch (3)
      If false then switch (3,primario) off:
      Print
    End switch
    ...
    ...
    Next
    
    Well it's just an idea of how to have controlled execution blocks
    Last edited by Edcronos; 22-01-2017 at 22:57.

  10. #10
    ThinBASIC includes an embedded Basic called Oxygen, Oxygen supports goto and gosub, see the sample scripts in the Oxygen folder
    I think the label must be a number.

Page 1 of 2 12 LastLast

Similar Threads

  1. Splitting code on multiple lines
    By TBUser54 in forum thinBasic General
    Replies: 2
    Last Post: 09-02-2012, 10:23
  2. Replies: 1
    Last Post: 11-11-2010, 14:29
  3. Playing with lines based on tutorial code
    By kryton9 in forum TBGL General
    Replies: 21
    Last Post: 04-02-2007, 00:27

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •