Results 1 to 6 of 6

Thread: How to swap two variables values without using a third variable?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    55
    Posts
    1,554
    Rep Power
    174

    Do you know: How to swap two variables values without using a third variable?

    just do some math:

    Uses "Console"
    
    Double a = 1.234
    Double b = 5.678
    
    console_writeLine("A = " + str$(a) )
    console_writeLine("B = " + str$(b) )
    
    a += b
    b = a - b
    a = a - b
    
    console_writeLine("A = " + str$(a) )
    console_writeLine("B = " + str$(b) )
    
    console_waitKey()
    
    How about Strings?

    Uses "Console"
    
    String A = "World !"
    String B = "Hello "
    
    Console_WriteLine(A + B)
    
    A += B
    B = Left$( A, Len(A) - Len(B) )
    A = Right$(A, Len(A) - Len(B) )
    
    console_writeLine(A + B)
    
    console_waitKey()
    
    or in thinBasic:
    '...
    Swap A,B
    '...
    
    Last edited by ReneMiner; 06-03-2013 at 20:16.
    I think there are missing some Forum-sections as beta-testing and support

Similar Threads

  1. Functions as Returned Values
    By danbaron in forum Science
    Replies: 0
    Last Post: 27-05-2011, 08:47
  2. Hex values
    By Michael Clease in forum thinDebug
    Replies: 2
    Last Post: 31-07-2010, 21:59
  3. byte values
    By Michael Clease in forum Sources, Templates, Code Snippets, Tips and Tricks, Do you know ...
    Replies: 1
    Last Post: 24-08-2009, 13:56
  4. Simple question about hex values
    By Michael Clease in forum thinBasic General
    Replies: 8
    Last Post: 26-05-2007, 10:09

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
  •