How to add condition in wordpress loop? [closed]

You don’t even need to write a conditional. This can be done by CSS.

Let’s have a simple example. Assuming your post’s structure is like this:

<div class="container-class">
    <p>
        <img src="https://wordpress.stackexchange.com/questions/275291/some-path"/>
        Some text
    </p>
</div>

You can set a rule to float the first image to left, and the second one to right:

.container-class img{
    float:left
}
.container-class:nth-child(2) img{
    float:right
}

This can also be done by doing a conditional, but it’s not necessary. However, if you insist on a conditional for the loop, you can set a value before the first loop, update it in the loop and then use the updated value in the next loop:

$class="some-class-name";
// First loop
if ( have_posts() ) {
   // Loop here
   $class="changed-class-name";
}

// Second loop
if ( have_posts() ) {
    // Loop here. Use the $class to add some class to your post. You 
    // can use this class to style your content.
}

You can even use numbers instead of strings. This is a vague question, with many solutions. Choose the one that you wish.